package com.tedu.day07springmvc.controller;

import com.tedu.day07springmvc.mapper.UserMapper;
import com.tedu.day07springmvc.pojo.dto.UserDto;
import com.tedu.day07springmvc.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
public class UserController {
    @Autowired
    private UserMapper userMapper;

 /*   @RequestMapping("/regUser")
    @ResponseBody
    public String regUser(HttpServletRequest request){

        System.out.println("开始处理用户登录信息");
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        String nickname=request.getParameter("nickname");
        String ageStr  =request.getParameter("age");
        System.out.println(username+","+password+","+nickname+","+ageStr);
        return "注册成功";
    }*/

    /*@RequestMapping("/regUser")
    @ResponseBody
    public String regUser(String username,String password,String nickname,int age){
        System.out.println("注册信息："+username+","+password+","+nickname+","+age);
        return "注册成功";*/

    @RequestMapping("/regUser")
    @ResponseBody
    public String regUser(UserDto userDto){
        System.out.println(userDto);
        User user=new User();
        user.setUsername(userDto.getUsername());
        user.setPassword(userDto.getPassword());
        user.setNickname(userDto.getNickname());
        user.setAge(userDto.getAge());
        user.setCreated(new Date());
        int num=userMapper.insertUser(user);
        return num>0?"成功":"失败";
    }
}
